﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Biblio2.LocalParsing;

namespace Biblio2.Configuration
{
    class FilesConfiguration
    {
        #region Constructor and Init
        public FilesConfiguration()
        {
            InitDefaultExtensionsList();
            InitDefaultFoldersList();
            InitDefaultExpressionsList();
            InitDefaultReplacementsList();
            InitDefaultFormatsList();
            InitDefaultTeamsList();
        }
        #endregion

        #region Extension
        #region Attributs
        /// <summary>
        /// 
        /// </summary>
        private List<String> m_extensionsList = null;
        #endregion Attributs
        #region Init
        /// <summary>
        /// Default initialisation of the list of extension
        /// </summary>
        private void InitDefaultExtensionsList()
        {
            if (m_extensionsList == null)
                m_extensionsList = new List<String>();
            
            m_extensionsList.Clear();
            m_extensionsList.Add("avi");
            m_extensionsList.Add("mpg");
        }
        #endregion Init
        #region Accesseurs
        public List<String> ExtensionsList
        {
            get 
            {
                if ((m_extensionsList == null) || (m_extensionsList.Count == 0))
                {
                    InitDefaultExtensionsList();
                }
                return m_extensionsList;
            }
            set
            {
                if (m_extensionsList != null)
                    m_extensionsList.Clear();

                m_extensionsList = null;
                m_extensionsList = value;
            }
        }
        #endregion Accesseurs
        #endregion Extension

        #region Folders
        #region Attributs
        private List<String> m_foldersList = null;
        #endregion Attributs
        #region Init
        private void InitDefaultFoldersList()
        {
            if (m_foldersList == null)
            {
                m_foldersList = new List<String>();
            }
            m_foldersList.Clear();
            m_foldersList.Add(@"C:\test\"); // TODO
        }
        #endregion Init
        #region Accesseurs
        public List<String> FoldersList
        {
            get
            {
                if ((m_foldersList == null) || (m_foldersList.Count == 0))
                    InitDefaultFoldersList();

                return m_foldersList;
            }
            set
            {
                if (m_foldersList != null)
                    m_foldersList.Clear();

                m_foldersList = null;
                m_foldersList = value;
            }
        }
        #endregion Accesseurs
        #endregion Folders

        #region Expressions
        #region Attributs
        private List<Expression> m_expressionsList = null;
        #endregion Attributs
        #region Init
        private void InitDefaultExpressionsList()
        {
            if (m_expressionsList == null)
                m_expressionsList = new List<Expression>();

            m_expressionsList.Clear();

            m_expressionsList.Add(new Expression(0, Expression.cType_Regexp, @"^.*?\\?(?<series>[^\\$]+?)(?:s(?<season>[0-3]?\d)\s?ep?(?<episode>\d\d)|(?<season>(?:[0-1]\d|(?<!\d)\d))x?(?<episode>\d\d))(?!\d)(?:[ .-]?(?:s\k<season>e?(?<episode2>\d{2}(?!\d))|\k<season>x?(?<episode2>\d{2}(?!\d))|(?<episode2>\d\d(?!\d))|E(?<episode2>\d\d))|)[ -.]*(?<title>(?![^\\]*?sample)[^\\]*?[^\\]*?)\.(?<ext>[^.]*)$"));
            m_expressionsList.Add(new Expression(1, Expression.cType_Regexp, @"^(?<series>[^\\$]+)\\[^\\$]*?(?:s(?<season>[0-1]?\d)ep?(?<episode>\d\d)|(?<season>(?:[0-1]\d|(?<!\d)\d))x?(?<episode>\d\d))(?!\d)(?:[ .-]?(?:s\k<season>e?(?<episode2>\d{2}(?!\d))|\k<season>x?(?<episode2>\d{2}(?!\d))|(?<episode2>\d\d(?!\d))|E(?<episode2>\d\d))|)[ -.]*(?<title>(?!.*sample)[^\\]*?[^\\]*?)\.(?<ext>[^.]*)$"));
            m_expressionsList.Add(new Expression(2, Expression.cType_Regexp, @"(?<series>[^\\\[]*) - \[(?<season>[0-9]{1,2})x(?<episode>[0-9\W]+)\](( |)(-( |)|))(?<title>(?![^\\]*?sample)[^$]*?)\.(?<ext>[^.]*)"));
            m_expressionsList.Add(new Expression(3, Expression.cType_Regexp, @"(?<series>[^\\$]*) - season (?<season>[0-9]{1,2}) - (?<title>(?![^\\]*?sample)[^$]*?)\.(?<ext>[^.]*)"));
            m_expressionsList.Add(new Expression(4, Expression.cType_Simple, @"<series> - <season>x<episode> - <title>.<ext>"));
            m_expressionsList.Add(new Expression(5, Expression.cType_Simple, @"<series>\Season <season>\Episode <episode> - <title>.<ext>"));
        }
        #endregion Init
        #region Accesseurs
        public List<Expression> ExpressionsList
        {
            get
            {
                if ((m_expressionsList == null) || (m_expressionsList.Count == 0))
                    InitDefaultExpressionsList();

                return m_expressionsList;
            }
            set
            {
                if (m_expressionsList != null)
                    m_expressionsList.Clear();

                m_expressionsList = null;
                m_expressionsList = value;
            }
        }
        #endregion Accesseurs
        #endregion Expressions

        #region Replacements
        #region Attributs
        private List<Replacement> m_replacementsList = null;
        #endregion Attributs
        #region Init
        private void InitDefaultReplacementsList()
        {
            if (m_replacementsList == null)
                m_replacementsList = new List<Replacement>();

            m_replacementsList.Clear();

            m_replacementsList.Add(new Replacement(0, 0, ".", @"<space>"));
            m_replacementsList.Add(new Replacement(1, 0, "_", @"<space>"));
            m_replacementsList.Add(new Replacement(2, 0, "-<space>", @"<empty>"));
            m_replacementsList.Add(new Replacement(3, 1, "720p", @"<empty>"));
            m_replacementsList.Add(new Replacement(4, 1, "1080i", @"<empty>"));
            m_replacementsList.Add(new Replacement(5, 1, "1080p", @"<empty>"));
            m_replacementsList.Add(new Replacement(6, 1, "x264", @"<empty>"));
        }
        #endregion Init
        #region Accesseurs
        public List<Replacement> ReplacementsList
        {
            get
            {
                if ((m_replacementsList == null) || (m_replacementsList.Count == 0))
                    InitDefaultReplacementsList();

                return m_replacementsList;
            }
            set
            {
                if (m_replacementsList != null)
                    m_replacementsList.Clear();

                m_replacementsList = null;
                m_replacementsList = value;
            }
        }
        #endregion Accesseurs
        #endregion Remplacements

        #region Formats
        #region Attributs
        private  List<String> m_formatsList = null;
        #endregion Attributs
        #region Init
        private void InitDefaultFormatsList()
        {
            if (m_formatsList == null)
                m_formatsList = new List<String>();

            m_formatsList.Clear();

            m_formatsList.Add("hdtv");
            m_formatsList.Add("pdtv");
            m_formatsList.Add("dsr");
            m_formatsList.Add("dvdrip");
        }
        #endregion Init
        #region Accesseurs
        public List<String> FormatsList
        {
            get
            {
                if ((m_formatsList == null) || (m_formatsList.Count == 0))
                    InitDefaultFormatsList();

                return m_formatsList;
            }
            set
            {
                if (m_formatsList != null)
                    m_formatsList.Clear();

                m_formatsList = null;
                m_formatsList = value;
            }
        }
        #endregion Accesseurs
        #endregion Formats

        #region Teams
        #region Attributs
        private List<String> m_teamsList = null;
        #endregion Attributs
        #region Init
        private void InitDefaultTeamsList()
        {
            if (m_teamsList == null)
                m_teamsList = new List<String>();

            m_teamsList.Clear();

            m_teamsList.Add("lol");
            m_teamsList.Add("aaf");
            m_teamsList.Add("xor");
            m_teamsList.Add("0tv");
        }
        #endregion Init
        #region Accesseurs
        public List<String> TeamsList
        {
            get
            {
                if ((m_teamsList == null) || (m_teamsList.Count == 0))
                    InitDefaultTeamsList();

                return m_teamsList;
            }
            set
            {
                if (m_teamsList != null)
                    m_teamsList.Clear();

                m_teamsList = null;
                m_teamsList = value;
            }
        }
        #endregion Accesseurs
        #endregion Teams
   
    }
}
